<template>
<div class="news">
  <div class="content_1">
    <div class="title">{{data.post_title}}</div>
    <div class="time">
      <div >{{data.create_time}}</div>
      <div class="t_item"><Icon class='icon_t' type="md-eye" />{{data.post_hits}}</div>
      <div class="t_item"><Icon class='icon_t' type="md-share-alt" />{{share_num}}</div>
    </div>
    <div>
      来源：{{data.post_source}}
    </div>
    <div class="content_nc" v-html="data.post_content"></div>
    <img src="~@a/img/gg.png" alt="">
  </div>
</div>
</template>
<script>
import { newsDetail,shareNum } from '@/api/api.js'
import wx from 'weixin-js-sdk'

export default {
  data(){
    return{
      data:{},
      share_num:0
    }
  },
  components:{
    
  },
  created(){
    this.getData()
  },
  mounted(){
    
  },
  methods:{
    getData(){
      newsDetail({id:this.$route.query.id,ip:returnCitySN["cip"]}).then(res=>{
        this.data = res.data
        this.share_num=this.data.share_num||0
        let time = setInterval(()=>{
          if(sessionStorage.url == this.$route.name){
            this.wxShare()
            clearInterval(time)
          }
        },100)
      })
    },
    wxShare(){
      var that=this
      wx.ready(() => {
        //分享给朋友
        wx.onMenuShareAppMessage({
          title: this.data.post_title+' | 园域', // 分享标题
          desc: this.data.post_excerpt, // 分享描述
          link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: this.data.thumbnail, // 分享图标
          type: '', // 分享类型,music、video或link，不填默认为link
          dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
          success(){
            // 用户确认分享后执行的回调函数
            that.shareNum()
          },
          cancel: function () {
          }
        })
        //分享到朋友圈
        wx.onMenuShareTimeline({
          title: this.data.post_title+' | 园域', // 分享标题
          link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: this.data.thumbnail, // 分享图标
          success(){
            // 用户确认分享后执行的回调函数
            that.shareNum()
          },
          cancel: function () {
            // 用户取消分享后执行的回调函数
          }
        })
      })
    },
    shareNum(){
      shareNum({id:this.$route.query.id}).then(res=>{
        this.share_num+=1
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.news{
  width: 100%;
  height: auto;
  padding: 0 15px;
  padding-bottom: 1rem;
  text-align: left;
  min-height: 800px;
  .content_1{
    width: 100%;
    overflow-x: hidden;
    .title{
      font-size: 22px;
      font-weight: 700;
      color: #1c1c1c;
      text-align: left;
      margin:10px 0;
    }
    .time{
      padding-bottom:20px;
      margin-bottom:20px;
      border-bottom: 1px solid #ddd;
      .t_item{
        float: right;
        margin-left:20px;
        margin-top:-20px;
        .icon_t{
          font-size: 16px;
          margin-right:5px;
        }
      }
    }
    .content_nc{
      background:#fff;
    }
    img{
      max-width: 100%;
    }
  }
}
</style>